//初始值
export const initState = {
    userInfo:sessionStorage.getItem('userInfo')?JSON.parse(sessionStorage.getItem('userInfo')):{}
}

//修改state
export const reducer = (state,action) =>{
    switch (action.type){
        case "changeUserInfo":
            return {
                ...state,
                userInfo:action.userInfo
            }
            default:
                return state;
    }
}
//action
export const actions =  {
    changeUserInfo:(userInfo)=>{
        if(userInfo.token){
            sessionStorage.setItem("userInfo",JSON.stringify(userInfo))
        }else{
            sessionStorage.removeItem("userInfo")
        }
        return {type:'changeUserInfo',userInfo}
    }
}